﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace Nirvana
{
    [CustomPropertyDrawer(typeof(Variate), true)]
    public class VariatePropertyDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            SerializedProperty hasValue = property.FindPropertyRelative("hasValue");
            SerializedProperty value = property.FindPropertyRelative("value");
            Rect rect = new Rect(position.x, position.y, position.width / 2f, position.height);
            Rect rect2 = new Rect(position.x + position.width / 2f, position.y, position.width / 2f, position.height);
            EditorGUI.BeginChangeCheck();
            hasValue.boolValue = EditorGUI.ToggleLeft(rect, label, hasValue.boolValue);
            GUI.enabled = hasValue.boolValue;
            EditorGUI.PropertyField(rect2, value, GUIContent.none);
            GUI.enabled = true;


            EditorGUI.EndProperty();
        }

        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return EditorGUIUtility.singleLineHeight;
        }
    }
}

